function getDPI() {
  var tempDiv = document.createElement("div");
  tempDiv.style.width = "1in";
  tempDiv.style.visibility = "hidden";
  document.body.appendChild(tempDiv);
  var dpi = tempDiv.offsetWidth;
  document.body.removeChild(tempDiv);
  return dpi;
}

function mmToPixel(mm, dpi) {
  // 1 inch = 25.4 mm
  var inches = mm / 25.4;
  var pixels = inches * dpi;
  return Math.round(pixels);
}

function a4SizeInPixels() {
  var dpi = getDPI();
  var width_mm = 210; // A4纸宽度，单位：毫米
  var height_mm = 297; // A4纸高度，单位：毫米
  var width_px = mmToPixel(width_mm, dpi);
  var height_px = mmToPixel(height_mm, dpi);
  return { width: width_px, height: height_px };
}

// 直接调用工具函数获取 A4 纸的像素尺寸
var a4_size = a4SizeInPixels();
console.log(
  "A4纸的像素尺寸：宽 " + a4_size.width + "px, 高 " + a4_size.height + "px"
);
export default a4SizeInPixels;
